package com.dyz.leetcode._05_sort;

import java.util.Comparator;

public class java_sort {
}

//方法一， 内部集成
class Persion implements Comparable<Persion>{
    private String name;
    private int age;

    public Persion() {
    }

    public Persion(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Persion{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    @Override
    public int compareTo(Persion o) {
        return this.age-o.age;
    }
}

//方法二 实现比较器
class PersonComparator implements Comparator<Persion>{

    @Override
    public int compare(Persion o1, Persion o2) {
        return o1.getAge()-o2.getAge();
    }
}
